//
//  ProjectDetailsViewController.m
//  Againstpoor
//
//  Created by 辰领科技 on 16/11/8.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "ProjectDetailsViewController.h"

@interface ProjectDetailsViewController ()
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroview;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *natureLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *progressLabel;
@property (weak, nonatomic) IBOutlet UILabel *departmentLabel;
@property (weak, nonatomic) IBOutlet UILabel *planningLabel;
@property (weak, nonatomic) IBOutlet UILabel *CompleteContentLabel;
@property (weak, nonatomic) IBOutlet UILabel *sizeLabel;


@property (weak, nonatomic) IBOutlet UIView *moneyView;
@property (weak, nonatomic) IBOutlet UILabel *totalInvestmentLabel;
@property (weak, nonatomic) IBOutlet UILabel *moneyOneLabel;
@property (weak, nonatomic) IBOutlet UILabel *moneyTwoLabel;
@property (weak, nonatomic) IBOutlet UILabel *SourcesFundingLabel;
@property (weak, nonatomic) IBOutlet UILabel *cashSituationLabel;
@property (weak, nonatomic) IBOutlet UILabel *label;

@property (weak, nonatomic) IBOutlet UIView *noteView;
@property (weak, nonatomic) IBOutlet UILabel *noteLabel;

@property (strong, nonatomic) NSDictionary *Dic;

@end

@implementation ProjectDetailsViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self getprojectDetail];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _Dic = [NSDictionary dictionary];
    [self initViewLayout];
}
- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    [self adaptiveViewLayout:self.moneyView];
    [self adaptiveViewLayout:self.noteView];
    
}


- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark - 扶贫详情
- (void)getprojectDetail {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setObject:_ID forKey:@"id"];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:F_projectDetail withHttpType:@"POST" withTag:F_F_projectDetail];
}

#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{

    if (tag==F_F_projectDetail) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            _Dic = database[@"data"];
            _titleLabel.text = _titleStr;
            NSString *_kind = [Common stringFromData:_Dic[@"KIND"]];
            if ([_kind isEqualToString:@"1"]) {
                _natureLabel.text = @"新建";
            } else if ([_kind isEqualToString:@"2"]) {
                _natureLabel.text = @"改建";
            } else if ([_kind isEqualToString:@"3"]) {
                _natureLabel.text = @"整修";
            } else if ([_kind isEqualToString:@"4"]) {
                _natureLabel.text = @"硬化";
            }
            _addressLabel.text = [NSString stringWithFormat:@"%@%@",[Common stringFromData:_Dic[@"AREA"]],[Common stringFromData:_Dic[@"COUNTRY"]]];
            _timeLabel.text = [Common stringFromData:_Dic[@"IMPLEMENT_TIME"]];
            NSString *_pressType = [Common stringFromData:_Dic[@"PRESS_TYPE"]];
            if ([_pressType isEqualToString:@"1"]) {
                _progressLabel.text = @"未开工";
            } else if ([_pressType isEqualToString:@"2"]) {
                _progressLabel.text = @"开工在建";
            } else if ([_pressType isEqualToString:@"3"]) {
                _progressLabel.text = @"已完成";
            } else if ([_pressType isEqualToString:@"4"]) {
                _progressLabel.text = @"已验收";
            }
            _departmentLabel.text = [Common stringFromData:_Dic[@"DEPARTMENT"]];
            _planningLabel.text = [Common stringFromData:_Dic[@"PLANT_CONTENT"]];
            _CompleteContentLabel.text = [Common stringFromData:_Dic[@"COMPLETE_CONTENT"]];
            _sizeLabel.text = [Common stringFromData:_Dic[@"DETAIL"]];
            _totalInvestmentLabel.text = [NSString stringWithFormat:@"￥%@万",[Common stringFromData:_Dic[@"TOTAL_INVESTMENT"]]];
            _moneyOneLabel.text = [NSString stringWithFormat:@"￥%@万",[Common stringFromData:_Dic[@"REPONS_PLANT"]]];
            _moneyTwoLabel.text = [NSString stringWithFormat:@"￥%@万",[Common stringFromData:_Dic[@"COMPLETE_ROUND"]]];
            _SourcesFundingLabel.text = [NSString stringWithFormat:@"财政专项扶贫资金 ￥%@万\n其他部门财政资金 ￥%@万\n社会扶贫资金 ￥%@万\n自筹资金 ￥%@万",[Common stringFromData:_Dic[@"SPECIAL_PRICE"]],[Common stringFromData: _Dic[@"otherPrice"]],[Common stringFromData:_Dic[@"SOCIAL_PRICE"] ],[Common stringFromData:_Dic[@"SELF_PRICE"] ]];
            _cashSituationLabel.text = [NSString stringWithFormat:@"投资金额 %@万\n资金计划文号：%@%@",[Common stringFromData:_Dic[@"ISSUED_PRICE"]],[Common stringFromData:_Dic[@"plantName"]],[Common stringFromData:_Dic[@"plantNum"]]];
            _noteLabel.text = [Common stringFromData:_Dic[@"REMARK"]];
            
            //        self.SourcesFundingLabel.text = @"财政专项扶贫资金 ￥200万\n其他部门财政资金 ￥0.00\n社会扶贫资金 ￥0.00\n自筹资金 ￥120万";
            //        self.cashSituationLabel.text = @"投资金额 198万\n资金计划问好：石柱特产发\n[2015]122号";
            [self.sizeLabel sizeToFit];
            [self.SourcesFundingLabel sizeToFit];
            [self.cashSituationLabel sizeToFit];
            [self.noteLabel sizeToFit];
            
            self.label.frame = CGRectMake(8*VerticalRatio(), _SourcesFundingLabel.frame.origin.y+_SourcesFundingLabel.frame.size.height+5*VerticalRatio(), 129, 17*VerticalRatio());
            self.cashSituationLabel.frame = CGRectMake(131*VerticalRatio(), _SourcesFundingLabel.frame.origin.y+_SourcesFundingLabel.frame.size.height+5*VerticalRatio(), 180*VerticalRatio(), _cashSituationLabel.frame.size.height);
            CGFloat sizeLabelHight = _sizeLabel.frame.size.height/VerticalRatio();
            if (sizeLabelHight == 0) {
                sizeLabelHight = 17;
            }
            self.moneyView.frame = CGRectMake(0, _sizeLabel.frame.origin.y+(sizeLabelHight+5)*VerticalRatio(), 320*VerticalRatio(), _cashSituationLabel.frame.origin.y+_cashSituationLabel.frame.size.height+5*VerticalRatio());
            self.noteView.frame = CGRectMake(0, _moneyView.frame.origin.y+_moneyView.frame.size.height, 320*VerticalRatio(), _noteLabel.frame.origin.y+_noteLabel.frame.size.height+5*VerticalRatio());
            CGFloat hight = _noteView.frame.origin.y+_noteView.frame.size.height;
            if (hight <= 504*VerticalRatio()) {
                hight = 505*VerticalRatio();
            }
            self.scroview.contentSize = CGSizeMake(0, hight);
        } else {
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{

    [self dismissWaitDialog];
    
}

@end
